var script = {
    stage01:{
        map:[
            [18,18,18,18,18,18,18,18,18,18,18,18,55,55,18,18,18],
            [18,18,18,17,17,17,17,17,17,17,17,17,55,55,17,17,18],
            [18,18,17,17,17,17,18,18,17,17,17,17,55,55,17,17,18],
            [18,17,17,17,18,18,18,18,18,17,17,55,55,17,17,17,18],
            [18,17,17,18,22,23,23,23,24,18,17,55,55,17,17,17,18],
            [18,17,17,18,25,28,26,79,27,18,55,55,17,17,17,17,18],
            [18,17,17,17,17,10,11,12,18,18,55,55,17,17,17,17,18],
            [18,18,17,17,10,16,16,16,11,55,55,17,17,17,17,17,18],
            [18,18,17,17,77,16,16,16,16,21,21,17,17,17,17,17,18],
            [18,18,17,17,77,16,16,16,16,55,55,17,17,17,17,17,18],
            [18,18,18,18,18,18,18,18,18,55,55,18,18,18,18,18,18]],
        mapdata:[
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,1],
            [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1],
            [1,0,0,0,1,1,1,1,1,0,0,1,1,0,0,0,1],
            [1,0,0,1,1,1,1,1,1,1,0,1,1,0,0,0,1],
            [1,0,0,1,1,1,0,1,1,1,1,1,0,0,0,0,1],
            [1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1],
            [1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1],
            [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
            [1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1],
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]],
        add:[
            {chara:"player",img:"mingren",x:5,y:6},
            {chara:"npc",img:"npc1",x:7,y:6},
            {chara:"npc",img:"npc1",x:3,y:3}
        ],
        talk:{
            talk1:[
                {img:"m",name:"鸣人",msg:"我是木叶村的鸣人，你是谁？"},
                {img:"n",name:"黑衣忍者甲",msg:"你就是鸣人？九尾还在你身体里吗？"}],
            talk2:[
                {img:"n",name:"黑衣忍者乙",msg:"鸣人，听说忍者大战就要开始了。"},
                {img:"m",name:"鸣人",msg:"真的吗？一定要想想办法啊。"}]
        },
        jump:[
            {at:{x:6,y:5},to:"stage02"}
        ]
    },
    stage02:{
        map:[
            [0,0,1,2,2,2,2,2,2,2,2,1,0,0,0],
            [0,0,1,3,5,5,1,5,5,5,5,1,0,0,0],
            [0,0,1,80,4,4,1,80,4,4,4,1,0,0,0],
            [0,0,1,80,4,4,1,80,8,7,8,1,0,0,0],
            [0,0,1,80,4,4,5,81,4,4,4,1,0,0,0],
            [0,0,1,2,2,2,6,4,4,4,4,1,0,0,0],
            [0,0,1,3,5,5,81,4,4,4,4,1,0,0,0],
            [0,0,1,80,4,4,4,4,4,4,9,1,0,0,0],
            [0,0,1,2,2,2,2,6,2,2,2,1,0,0,0]
        ],
        mapdata:[
            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
            [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1],
            [1,1,1,0,0,0,1,0,0,0,0,1,1,1,1],
            [1,1,1,0,0,0,1,0,0,1,0,1,1,1,1],
            [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1],
            [1,1,1,1,1,1,0,0,0,0,0,1,1,1,1],
            [1,1,1,0,0,0,0,0,0,0,0,1,1,1,1],
            [1,1,1,0,0,0,0,0,0,0,1,1,1,1,1],
            [1,1,1,1,1,1,1,0,1,1,1,1,1,1,1]
        ],
        add:[
            {chara:"player",img:"mingren",x:7,y:8},
            {chara:"npc",img:"npc1",x:8,y:3},
            {chara:"npc",img:"npc1",x:10,y:3}
        ],
        talk:{
            talk1:[
                {img:"m",name:"鸣人",msg:"你们在干什么啊？"},
                {img:"n",name:"黑衣忍者甲",msg:"我们在喝茶。"}
            ],
            talk2:[
                {img:"n",name:"黑衣忍者乙",msg:"我们在喝茶，你不要打扰我们。"},
                {img:"m",name:"鸣人",msg:"....."}
            ]
        },
        jump:[
            {at:{x:7,y:8},to:"stage01"}
        ]
    }
};

//根据脚本，初始化游戏画面
function initSctipt(){

    mapLayer.x = 0;
    mapLayer.y = 0;
    charaLayer.x = 0;
    charaLayer.y = 0;

    mapLayer.removeAllChild();
    charaLayer.removeAllChild();
    effectLayer.removeAllChild();
    talkLayer.removeAllChild();

    map = stage.map;
    mapdata = stage.mapdata;

    talkScriptList = stage.talk;

    addMap(0,0);
    delMap();

    addChara();
}

//游戏场景跳转测试
function checkJump(){
    var jump = stage.jump;
    var jumpstage;
    for(var i = 0 ; i < jump.length;i++){
        jumpstage = jump[0];
        if(player.x == jumpstage.at.x *32 && player.y == jumpstage.at.y *32){
            stage = script[jumpstage.to];
            initSctipt(stage);
            return;
        }
    }
}